package net.mingsoft.document.enums;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.helpers.MessageFormatter;

/**
 * @author gengfa
 * @date 22/01/26
 */
public enum FileOperateType {

    /**
     * 移动 复制
     */
    CREATE("CREATE", "创建文件", null),
    DELETE("DELETE", "删除文件", "该{}已被删除"),
    SHARE("SHARE", "分享文件", "您收到一个新的分享"),
    MOVE("MOVE", "移动文件", "该{}移动至\"{}\""),
    COPY("COPY", "复制文件", "该{}复制至\"{}\""),
    MODIFY("MODIFY", "修改文件", null),
    GRANT("GRANT", "文件授权", null),
    DOWNLOAD("DOWNLOAD", "下载文件", null),
    VIEW("VIEW", "查看文件", null),
    MV("MV", "移动", null),
    CP("CP", "复制", null),
    UNKNOWN("UNKNOWN", "未知操作", null);

    private String type;

    private String desc;

    private String messageContent;

    FileOperateType(String type, String desc, String messageContent) {
        this.type = type;
        this.desc = desc;
        this.messageContent = messageContent;
    }

    public static String getOpDesc(String op) {
        for (FileOperateType value : FileOperateType.values()) {
            if (StringUtils.equals(value.getType(), op)) {
                return value.getDesc();
            }
        }
        return UNKNOWN.getDesc();
    }

    public static String getMessageContent(FileOperateType type, String... params) {
        return MessageFormatter.arrayFormat(type.getMessageContent(), params).getMessage();
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public String getMessageContent() {
        return messageContent;
    }

    public void setMessageContent(String messageContent) {
        this.messageContent = messageContent;
    }
}
